package com.lxz.datasource.controller;

import com.lxz.datasource.dao.MyUserRepository;
import com.lxz.datasource.entity.MyUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("myUser")

public class MyUserController {

    private static final Logger log = LoggerFactory.getLogger(MyUserController.class);
    @Autowired
    private MyUserRepository userRepository;

    @PostMapping("add")
    public @ResponseBody String addNewUser(MyUser user){
        if (user == null) {
            return "无数据";
        }
        userRepository.save(user);
        return "成功";
    }

    @GetMapping("all")
    public @ResponseBody
    Iterable<MyUser> getAllUsers() {
        return userRepository.findAll();
    }

    @GetMapping("login")
    public @ResponseBody
    String addNewUser(@RequestParam String username, @RequestParam String password) {
        return "成功";
    }


    public static void main(String[] args) {
        log.trace("trace level");
        log.debug("debug level");
        log.info("info level");
        log.warn("warn level");
        log.error("error level");
    }
}
